﻿using System;
using System.Collections.Generic;
using System.Text;
using CommandLine;
using CommandLine.Text;

namespace SchTasksSetPriority
{
    /// <summary>
    /// The options for this program parsed from the command line arguments.
    /// </summary>
    class Options
    {
        /// <summary>
        /// Gets the valid values for the priority input.
        /// </summary>
        /// <returns>The valid values.</returns>
        public static string GetPriorityValues()
        {
            var validValues = new System.Text.StringBuilder();
            foreach (var validValue in Enum.GetNames(typeof(System.Diagnostics.ProcessPriorityClass)))
            {
                if (validValues.Length > 0)
                {
                    validValues.Append(", ");
                }
                validValues.Append(validValue);
            }
            return validValues.ToString();
        }

        [Option("s", "server", DefaultValue = null, HelpText = "The server to connect. Defaults to local.")]
        public string Server { get; set; }

        [Option(null, "user", DefaultValue = null, HelpText = "The user id to register the task to run under.")]
        public string TaskRunAsUser { get; set; }

        [Option(null, "password", DefaultValue = null, HelpText = "The password of the user to register the task to run under.")]
        public string TaskRunAsPassword { get; set; }

        [Option("t", "task-name", Required = true, DefaultValue = null, HelpText = "The name of the task to set it's priority.")]
        public string TaskName { get; set; }
        
        [Option("p", "priority", DefaultValue = null, HelpText = "The priority to set on the task. Valid values are Normal, Idle, High, RealTime, BelowNormal, AboveNormal. If not provided, then the current priority of the task will be written to the console.")]
        public string Priority { get; set; }

        [HelpOption]
        public string GetUsage()
        {
            var help = new HelpText
            {
                Heading = new HeadingInfo("SchTasksSetPriority", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()),
                //Copyright = new CopyrightInfo("<>", 2012),
                AdditionalNewLineAfterOption = true,
                AddDashesToOption = true,
            };
            help.AddPreOptionsLine("A command line tool to set the priority of Tasks in the Windows Task Scheduler.");
            help.AddPreOptionsLine("");
            help.AddPreOptionsLine("Usage: SchTasksSetPriority -t MyFavoriteTask -p Normal");
            help.AddOptions(this);
            return help;
        }
    }
}
